import unittest
import os.path

from kivy.lang import Builder

from add_player import *
from presenter_mock import *


class APTest(unittest.TestCase):
    def setUp(self):
        Builder.load_file(os.path.join(os.path.dirname(__file__),
                                       'addplayer.kv'))

    def test_empty(self):
        """
        Test empty list of users
        """
        gamestate = GameState(Players([]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        tmp = AddPlayerScreen(gamestate, presenter)
        tmp.player_name = 'AAA'
        tmp.on_add_user_pressed()
        self.assertEquals(tmp.game_state.current_added_player.name, 'AAA')

    def test_one(self):
        """
        Test list of users with one player
        """
        gamestate = GameState(Players([Player('User1', [])]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        tmp = AddPlayerScreen(gamestate, presenter)
        tmp.player_name = 'AAA'
        tmp.on_add_user_pressed()
        self.assertEquals(tmp.game_state.current_added_player.name, 'AAA')
        self.presenter = PresenterMock(Phase.START_GAME)

    def test_unacceptable(self):
        """
        Test unacceptable player names
        """
        gamestate = GameState(Players([Player('User1', [])]), Hat([]),
                              GameRound(0, [], '', ['', '']),
                              Phase.ADD_PLAYER, [], None,
                              Settings(0, 0))
        presenter = PresenterMock(Phase.ADD_WORDS)
        tmp = AddPlayerScreen(gamestate, presenter)
        tmp.update_name('')
        self.assertEquals(tmp.to_add_button.enabled, False)


if __name__ == '__main__':
    unittest.main()
